appModule.service("sshClientService", ["$ionicPopup", function($ionicPopup) {
    var sshClient = null;
    try {
        sshClient = cordova.require("lee-plugin-sshclient.sshclient")
    } catch (e) {
        $ionicPopup.alert({
            title: '初始化SSH客户端模块失败！' + e
        });
        return true;
    }
    var service = {
        connect: function(sshSession, successCallback, errorCallback) {
            if(! sshClient) {
                errorCallback && errorCallback("程序未初始化...");
            }
            console.info("连接SSH服务器: " + JSON.stringify(sshSession));
            var sshSessionConfig = sshSession.sshSessionConfig;
            sshClient.connect(sshSession.id, sshSessionConfig.host, sshSessionConfig.port, sshSessionConfig.user, sshSessionConfig.password, successCallback, errorCallback);
        },
        execute: function(sshSessionId, command, successCallback, errorCallback) {
            sshClient.execute(sshSessionId, command, successCallback, errorCallback);
        },
        close: function(sshSessionId, successCallback, errorCallback) {
            sshClient.close(sshSessionId, successCallback, errorCallback);
        }
    };
    return service;
}]);